import redis
# str  字符串
# byte  字节串  b'hellokitty'
def main():
    client = redis.Redis(host='192.168.84.89', port=6379,
                         password='1qaz2wsx')
    # client.set('username','hellokitty',ex=300)
    client.set('zhjname','张红军')
    # 查看键值的存活时间
    print(client.ttl('username'))
    # 查看键值  .decode 中文解码
    print(client.get('username'))
    print(client.get('zhjname').decode())
    client.rpush('list1',12,21,3,21,23,21,23,21,2)
    print(client.lrange('list1',0,-1))
    client.hset('stu1','id','1001')
    client.hset('stu1', 'name', '张献忠')
    print(client.hgetall('stu1'))
    print(client.hget('stu1','name').decode())

if __name__ == '__main__':
    main()

